package com.jl.jlapp.utils;

import android.content.Context;
import android.os.Environment;

import java.io.File;
import java.math.BigDecimal;

public class DataCleanManager {
    public static void clearAllCache(Context paramContext) {
        deleteDir(paramContext.getCacheDir());
        if (Environment.getExternalStorageState().equals("mounted")) {
            deleteDir(paramContext.getExternalCacheDir());
        }
    }

    private static boolean deleteDir(File paramFile) {
        if ((paramFile != null) && (paramFile.isDirectory())) {
            String[] arrayOfString = paramFile.list();
            int i = 0;
            while (i < arrayOfString.length) {
                if (!deleteDir(new File(paramFile, arrayOfString[i]))) {
                    return false;
                }
                i += 1;
            }
        }
        return paramFile.delete();
    }

    private static long getFolderSize(File file) {
        long size = 0;
        try {
            File[] fileList = file.listFiles();
            for (int i = 0; i < fileList.length; i++) {
                if (fileList[i].isDirectory()) size = size + getFolderSize(fileList[i]);
                else size = size + fileList[i].length();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return size;
    }


    public static String getFormatSize(double paramDouble) {
        double d = paramDouble / 1024.0D;
        if (d < 1.0D) {
            return "0K";
        }

        BigDecimal localBigDecimal = null;
        paramDouble = d / 1024.0D;
        if (paramDouble < 1.0D) {
            localBigDecimal = new BigDecimal(Double.toString(d));
            return localBigDecimal.setScale(2, 4).toPlainString() + "KB";
        }
        d = paramDouble / 1024.0D;
        if (d < 1.0D) {
            localBigDecimal = new BigDecimal(Double.toString(paramDouble));
            return localBigDecimal.setScale(2, 4).toPlainString() + "MB";
        }
        paramDouble = d / 1024.0D;
        if (paramDouble < 1.0D) {
            localBigDecimal = new BigDecimal(Double.toString(d));
            return localBigDecimal.setScale(2, 4).toPlainString() + "GB";
        }
        localBigDecimal = new BigDecimal(paramDouble);
        return localBigDecimal.setScale(2, 4).toPlainString() + "TB";
    }

    public static String getTotalCacheSize(Context paramContext)
            throws Exception {
        long l2 = getFolderSize(paramContext.getCacheDir());
        long l1 = l2;
        if (Environment.getExternalStorageState().equals("mounted")) {
            l1 = l2 + getFolderSize(paramContext.getExternalCacheDir());
        }
        return getFormatSize(l1);
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/utils/DataCleanManager.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */